package com.tianji.promotion.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;


@Configuration
public class PromotionConfig {

    @Bean
    public Executor generateExchangeCodeExecutor(){
        ThreadPoolTaskExecutor executor=new ThreadPoolTaskExecutor();
        //1.设置核心线程池大小
        executor.setCorePoolSize(2);

        //2.设置最大线程池大小
        executor.setMaxPoolSize(6);

        //3.设置队列大小
        executor.setQueueCapacity(200);

        //4.设置线程池名称
        executor.setThreadNamePrefix("exchange-code-handler-");

        //5.设置拒绝策略
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        //初始化
        executor.initialize();
        return executor;
    }
}
